/*
 * Copyright (c) 2017 zhangcm. All Rights Reserved.
 */
package com.jnzc.ocr.rest.app.shop.controller.app;

import com.jnzc.ocr.common.utils.DateUtils;
import com.jnzc.ocr.common.vo.UserVo;
import com.jnzc.ocr.dependencies.rest.base.BaseController;
import com.jnzc.ocr.rest.app.shop.param.app.AppCountRevenueParam;
import com.jnzc.ocr.serv.shop.api.ShopCountApi;
import com.jnzc.ocr.serv.shop.entity.ShopCountRevenue;
import com.jnzc.ocr.serv.shop.filter.ShopCountRevenueFilter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author zhangcm
 * @version 1.0, 2017/10/7
 */
@Api(tags = {"app - 统计接口"})
@RestController
@RequestMapping("/app/count")
public class AppCountController extends BaseController {

    @Autowired
    private ShopCountApi shopCountApi;

    @ApiOperation(value = "营收简报")
    @GetMapping("/revenue")
    public ShopCountRevenue revenue(AppCountRevenueParam param){
        UserVo userVo = super.get();
        ShopCountRevenueFilter filter = new ShopCountRevenueFilter();
        filter.setShopId(userVo.getShopId());
        filter.setBeginDate(param.getBeginDate());
        filter.setEndDate(DateUtils.addDay(param.getEndDate(), 1));
        return shopCountApi.findRevenue(filter);
    }

    @ApiOperation(value = "营收趋势")
    @GetMapping("/revenueList")
    public List<ShopCountRevenue> revenueList(AppCountRevenueParam param){
        UserVo userVo = super.get();
        ShopCountRevenueFilter filter = new ShopCountRevenueFilter();
        filter.setShopId(userVo.getShopId());
        filter.setBeginDate(param.getBeginDate());
        filter.setEndDate(DateUtils.addDay(param.getEndDate(), 1));
        return shopCountApi.listRevenue(filter);
    }
}
